; Version 1.0 by Maxwell Hallum and Jonathan Musser

(defglobal MAIN ?*LeadershipScore* = 0)

(defglobal MAIN ?*SkillPts* = 0)

(deftemplate MAIN::SkillsExp
   (slot skill (type STRING)))

(deftemplate MAIN::LeadershipExp
   (slot position (type STRING))
   (slot business (type STRING))
   (slot duration (type FLOAT)))

(deffacts MAIN::desiredSkills
   (PrefSkill "C++")
   (PrefSkill "Ada")
   (PrefSkill "C")
   (PrefSkill "CSS"))

(defrule MAIN::is-CEO
   (LeadershipExp (position ?pos) (duration ?dur))
   (test (= (str-compare ?pos "CEO") 0))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 10 (sqrt ?dur)))))

(defrule MAIN::is-President
   (LeadershipExp (position ?pos) (duration ?dur))
   (test (= (str-compare ?pos "President") 0))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 10 (sqrt ?dur)))))

(defrule MAIN::is-CTO
   (LeadershipExp (position ?pos) (duration ?dur))
   (test (= (str-compare ?pos "CTO") 0))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 9 (sqrt ?dur)))))

(defrule MAIN::is-Director
   (LeadershipExp (position ?pos) (duration ?dur))
   (test (= (str-compare ?pos "Director") 0))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 8 (sqrt ?dur)))))

(defrule MAIN::is-Manager
   (LeadershipExp (position ?pos) (duration ?dur))
   (test (= (str-compare ?pos "Manager") 0))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 5 (sqrt ?dur)))))

(defrule MAIN::is-Senior
   (LeadershipExp (position ?pos) (duration ?dur))
   (test (= (str-compare ?pos "Senior") 0))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 3 (sqrt ?dur)))))

(defrule MAIN::is-Lead
   (LeadershipExp (position ?pos) (duration ?dur))
   (and (or  (test (= (str-compare ?pos "Lead") 0))
             (test (= (str-compare ?pos "Leader") 0))))
   =>
   (bind ?*LeadershipScore* (+ ?*LeadershipScore* (* 4 (sqrt ?dur)))))

(defrule MAIN::OrdinarySkill
   (SkillsExp (skill ?skill))
   (forall
        (PrefSkill ?pskill)
        (test (not (= (str-compare ?skill ?pskill) 0))))
   =>
   (bind ?*SkillPts* (+ ?*SkillPts* 1)))

(defrule MAIN::PreferredSkill
   (SkillsExp (skill ?skill))
   (PrefSkill ?skill)
   =>
   (bind ?*SkillPts* (+ ?*SkillPts* 5)))

(defrule MAIN::Totaler
   (declare (salience -1))
   =>
   (bind ?total (+ ?*LeadershipScore* ?*SkillPts*))
   (printout t "Leadership score: " ?*LeadershipScore* crlf)
   (printout t "Skill score: " ?*SkillPts* crlf)
   (printout t "Total score: " ?total crlf))

